package com.aiyige.utils.widget;

import android.app.Activity;
import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.aiyige.R;


public class TitleLayout extends RelativeLayout {

	private TextView titleText;

	private View backLayout;

	private ImageView backImage;

	private View bottomLine;

	public TitleLayout(Context context) {
		super(context);
		init(context);
	}

	private void init(Context context) {
		LayoutInflater.from(context).inflate(R.layout.title_layout, this);
		titleText = (TextView) findViewById(R.id.title_text);
		backLayout = findViewById(R.id.back_layout);
		backImage = (ImageView) findViewById(R.id.back_iv);
		bottomLine = findViewById(R.id.bottomline);
		backImage.setOnClickListener(backListener);
		backLayout.setOnClickListener(backListener);
	}

	public TitleLayout(Context context, AttributeSet attrs) {
		super(context, attrs);
		init(context);
	}


	public void setBottomLineGone() {
		if (bottomLine != null) {
			bottomLine.setVisibility(GONE);
		}
	}

	OnClickListener backListener = new OnClickListener() {

		@Override
		public void onClick(View arg0) {
			((Activity) getContext()).setResult(((Activity) getContext()).RESULT_OK);;
			((Activity) getContext()).finish();
		}
	};

	public void setTitleName(String titleName) {
		if (titleText != null) {
			titleText.setText(titleName);
		}
	}

}
